;
(function () {
  $.extend({
    strfmt: function () { alert(2); }
  });
})(jQuery);

/**
 * String.prototype.[method name] used to format string with params.
 * use as:
 * var tpl = "i am {0}，now {1}.";
 * console.info(tpl.format("rex", 22));
 * var tpl = "i am {name}，now {age}.";
 * console.info(tpl.format({"name":"rex", "age":22}));
 */
String.prototype.format = function(args) {
    var result = this;
    if (arguments.length > 0) {
        if (arguments.length == 1 && typeof (args) == "object") {
            for (var key in args) {
                if(args[key]!=undefined){
                    var reg = new RegExp("({" + key + "})", "g");
                    result = result.replace(reg, args[key]);
                }
            }
        }
        else {
            for (var i = 0; i < arguments.length; i++) {
                if (arguments[i] != undefined) {
                    var reg = new RegExp("({[" + i + "]})", "g");
                    result = result.replace(reg, arguments[i]);
                }
            }
        }
    }
    return result;
};

/**
 * var tpl = "i am %1，now %2.";
 * console.info(String.format(tpl, "rex", 22));
 */
String.format = function(str) {
  var args = arguments, re = new RegExp("%([1-" + args.length + "])", "g");
  return String(str).replace(
    re,
    function($1, $2) {
      return args[$2];
    }
  );
};

/**
 * Array.prototype.[method name] allows you to define/overwrite an objects method
 * needle is the item you are searching for
 * this is a special variable that refers to "this" instance of an Array.
 * returns true if needle is in the array, and false otherwise
 */
Array.prototype.contains = function (needle) {
  // for (var i = 0; i < this.length; i++) {
  // // for (i in this) {
  //   if (this[i] == needle) return true;
  // }
  // return false;
  return RegExp(needle).test(this);
};